package cn.itsource.pet.service.impl;

import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDetail;
import cn.itsource.pet.mapper.PetDetailMapper;
import cn.itsource.pet.service.IPetService;
import cn.itsource.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zj
 * @since 2022-12-12
 */
@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetDetailMapper petDetailMapper;

    /**
     * 重写add方法
     *  添加宠物需要往t_pet和t_pet_detail两张表中添加数据
     * @param pet
     */
    @Transactional
    @Override
    public void add(Pet pet) {
        //保存宠物 返回主键
        super.add(pet);
        //保存宠物详情
        PetDetail petDetail = pet.getPetDetail();
        //设置外键
        petDetail.setPetId(pet.getId());
        petDetailMapper.save(petDetail);
    }
}
